package team.stride.database.crud.tracks;

import java.util.List;

import team.stride.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TracksAdapter extends BaseAdapter
{
	private BDTracksActivity activity;
	private List<TracksItem> tracksList;

	public TracksAdapter(BDTracksActivity activity, List<TracksItem> mapslist)
	{
		this.activity = activity;
		this.tracksList = mapslist;
	}

	public int getCount()
	{
		return tracksList.size();
	}

	public TracksItem getItem(int position)
	{
		return tracksList.get(position);
	}

	public long getItemId(int position)
	{
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup viewGroup)
	{
		final TracksItem entry = tracksList.get(position);
		if (convertView == null)
		{
			LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.bd_tracks_row, null);
		}
		TextView tracksName = (TextView) convertView.findViewById(R.id.tracksName);
		tracksName.setText(entry.getName());

		TextView tracksLen = (TextView) convertView.findViewById(R.id.tracksLen);
		tracksLen.setText(entry.getLenght() + " Km");

		
		TextView tracksGPX = (TextView) convertView.findViewById(R.id.tracksGPX);
		tracksGPX.setText(entry.getGpx());
		
		TextView tracksDetails = (TextView) convertView.findViewById(R.id.tracksDetails);
		tracksDetails.setText(entry.getDetails());

		ImageView tracksImg = (ImageView) convertView.findViewById(R.id.tracksImg);
		tracksImg.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				activity.showDialog(BDTracksActivity.MODIFY_DIALOG, entry);
			}
		});
		return convertView;
	}
}
